import tkinter as tk
import tkinter.filedialog
from tkinter.scrolledtext import ScrolledText
import os
import cv2

def main():
    top = tk.Tk()
    top.title("探伤终端")
    global contents
    global savepath
    savepath = '.\\'
    contents = ScrolledText(font=25)
    contents.pack(side=tk.BOTTOM, expand=True, fill=tk.BOTH)
    tk.Button(text="开始探伤",command=SysCommand).pack(side=tk.LEFT)
    tk.Button(text="退出", command=exit).pack(side=tk.LEFT)
    tk.mainloop()

def Capture():
    cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)  # 打开摄像头
    ret, frame = cap.read()
    cv2.imshow("cap", frame)
    cv2.imwrite("origin.png", frame)

def SysCommand():
    contents.insert(tk.END, "探伤开始！请放入零件！\n")
    contents.insert(tk.END, "充磁中...\n")
    os.system("Mag")
    contents.insert(tk.END, "充磁结束，开启紫外灯，拍摄中\n")
    os.system("UVLight")
    Capture()
    os.system("python3 Analyze.py")
    os.system("python3 eval.py")
    contents.insert(tk.END, "探伤结束，损伤图及对比情况如图所示\n")

if __name__ == '__main__':
    main()